package org.bitterorange.flansmodslain.actions;

import org.bitterorange.flansmodslain.FlansModSlain;
import org.bitterorange.flansmodslain.models.PlayerRankUpEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class Point {
    public static void add(Player player, int points) {
        int rankIndexBefore = FlansModSlain.rankIndexOf(player);
        FlansModSlain.addPoints(player, points);
        int rankIndexAfter = FlansModSlain.rankIndexOf(player);
        if (rankIndexAfter > rankIndexBefore) {
            Bukkit.getServer().getPluginManager().callEvent(new PlayerRankUpEvent(player,
                    rankIndexAfter,
                    FlansModSlain.rankOf(player)));
        }
    }

    public static void set(Player player, int points) {
        int rankIndexBefore = FlansModSlain.rankIndexOf(player);
        FlansModSlain.setPoints(player, points);
        int rankIndexAfter = FlansModSlain.rankIndexOf(player);
        if (rankIndexAfter > rankIndexBefore) {
            Bukkit.getServer().getPluginManager().callEvent(new PlayerRankUpEvent(player,
                    rankIndexAfter,
                    FlansModSlain.rankOf(player)));
        }
    }

    public static int get(Player player) {
        return FlansModSlain.getPoints(player);
    }

    public static String getRankOf(Player player) {
        return FlansModSlain.rankOf(player);
    }

    public static int getRankIndexOf(Player player) {
        return FlansModSlain.rankIndexOf(player);
    }
}
